package com.gitee.minimalismstyle.fresh.common.web.deserializer

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId


class NumberToLocalDateDeserializer : JsonDeserializer<LocalDate>() {
    override fun deserialize(p0: JsonParser, p1: DeserializationContext): LocalDate? {
        val timestamp: Long = p0.valueAsLong
        return if (timestamp > 0) {
            LocalDate.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault())
        } else {
            null
        }
    }
}